home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 2099 / 2099.xpi / chrome / overlay.xul < prev   
Extensible Markup Language  |  2006-03-13  |  12KB  |  366 lines

  1. <?xml version="1.0"?>
  2. <overlay id="repagination"
  3. xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 
  4. xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  5. xmlns:html="http://www.w3.org/1999/xhtml"
  6. >
  7.  
  8. <script type="application/x-javascript" src="chrome://repagination/content/javascript.js"/>
  9.  
  10. <script type="application/x-javascript">
  11. <![CDATA[
  12.  
  13. /* ***** BEGIN LICENSE BLOCK *****
  14.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  15.  *
  16.  * The contents of this file are subject to the Mozilla Public License Version
  17.  * 1.1 (the "License"); you may not use this file except in compliance with
  18.  * the License. You may obtain a copy of the License at
  19.  * http://www.mozilla.org/MPL/
  20.  *
  21.  * Software distributed under the License is distributed on an "AS IS" basis,
  22.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  23.  * for the specific language governing rights and limitations under the
  24.  * License.
  25.  *
  26.  * The Original Code is Paste and Go.
  27.  *
  28.  * The Initial Developer of the Original Code is Jens Bannmann.
  29.  * Portions created by the Initial Developer are Copyright (C) 2003
  30.  * the Initial Developer. All Rights Reserved.
  31.  *
  32.  * Contributor(s) (alphabetical order):
  33.  *  Jens Bannmann <jens.b@web.de>
  34.  *  Oliver Aeberhard <aeberhard@gmx.ch>
  35.  *
  36.  * Alternatively, the contents of this file may be used under the terms of
  37.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  38.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  39.  * in which case the provisions of the GPL or the LGPL are applicable instead
  40.  * of those above. If you wish to allow use of your version of this file only
  41.  * under the terms of either the GPL or the LGPL, and not to allow others to
  42.  * use your version of this file under the terms of the MPL, indicate your
  43.  * decision by deleting the provisions above and replace them with the notice
  44.  * and other provisions required by the GPL or the LGPL. If you do not delete
  45.  * the provisions above, a recipient may use your version of this file under
  46.  * the terms of any one of the MPL, the GPL or the LGPL.
  47.  *
  48.  * ***** END LICENSE BLOCK ***** */
  49.  
  50.  
  51. repagination = 
  52. {    
  53.     regxNumber : /[0-9]+/,
  54.     regx2Numbers : /[0-9]+[^0-9][0-9]+/,
  55.     getContents : function(aURL)
  56.     {
  57.         var ioService=Components.classes["@mozilla.org/network/io-service;1"]
  58.             .getService(Components.interfaces.nsIIOService);
  59.         var scriptableStream=Components
  60.             .classes["@mozilla.org/scriptableinputstream;1"]
  61.             .getService(Components.interfaces.nsIScriptableInputStream);
  62.         var channel=ioService.newChannel(aURL,null,null);
  63.         var input=channel.open();
  64.         scriptableStream.init(input);
  65.         var str=scriptableStream.read(input.available());
  66.         scriptableStream.close();
  67.         input.close();
  68.         return str;
  69.     },
  70.     blast : function(num,isslide)
  71.     {    
  72.  
  73.         var focusElement = document.commandDispatcher.focusedElement;
  74.         if(focusElement == null)
  75.         {
  76.             return;
  77.         }
  78.         var doc = focusElement.ownerDocument;
  79.         /* inject script */
  80.         
  81.         var repaginator = new Repaginator();
  82.  
  83.         if(isslide != null && num != null)
  84.         {
  85.             repaginator.seconds = num;
  86.             repaginator.slideshow = true;
  87.             repaginator.nolimit = true;
  88.         }
  89.         else if(num != null)
  90.         {
  91.             repaginator.slideshow = false;
  92.             repaginator.pagelimit = num;
  93.             repaginator.nolimit = false;
  94.         }
  95.         else
  96.         {
  97.             repaginator.slideshow = false;
  98.             repaginator.nolimit = true;
  99.         }
  100.         var searchpathtext = '';
  101.         var range = focusElement.ownerDocument.createRange();
  102.         range.selectNode(focusElement);
  103.         searchpathtext = range.toString();
  104.         var query = '//body';
  105.         if(searchpathtext != null && searchpathtext != '')
  106.         {
  107.             query 
  108.                 = '//a[.=\''+searchpathtext+'\'][position()=last()]';
  109.         }
  110.         else
  111.         {
  112.  
  113.             if(focusElement.getAttribute('value') != '' && 
  114.             focusElement.getAttribute('value') != null)
  115.             {
  116.                 var input_value = focusElement.getAttribute('value');
  117.  
  118.                 if(input_value != '')
  119.                 {
  120.                     query = '//input[@value=\''+input_value+'\'][position()=last()]/ancestor::a';
  121.                 }
  122.             }
  123.             else if(focusElement.getAttribute('src') != '' && 
  124.             focusElement.getAttribute('src') != null)
  125.             {
  126.                 
  127.                 var img_src = focusElement.getAttribute('src');
  128.  
  129.                 if(img_src != '')
  130.                 {
  131.                     query = '//img[@src=\''+img_src+'\'][position()=last()]/ancestor::a';
  132.                     
  133.                 }
  134.             }
  135.             else if(focusElement instanceof HTMLAnchorElement)
  136.             {
  137.                 /* get src */
  138.                 var srcObj 
  139.                     = repagination.returnFirstSnapshot(doc, focusElement, 'child::*[@src]');
  140.                 if(srcObj != null)
  141.                 {
  142.                     var img_src = srcObj.getAttribute('src');
  143.     
  144.                     if(img_src != '')
  145.                     {
  146.                         query = '//img[@src=\''+img_src+'\'][position()=last()]/ancestor::a';
  147.                     }
  148.                 }    
  149.             }
  150.         }
  151.         
  152.  
  153.         repaginator.query=query;
  154.         repaginator.numberToIncrement = null;
  155.         repaginator.attemptToIncrement = false;
  156.         
  157.         if (!this.regx2Numbers.test(query))
  158.         {
  159.             var test = this.regxNumber.exec(query);
  160.             if (test)
  161.             {
  162.                 repaginator.attemptToIncrement = true;
  163.                 repaginator.numberToIncrement = test[0];
  164.             }
  165.         }
  166.  
  167.         repaginator.blast(doc.defaultView);
  168.     },
  169.  
  170.     // Register each repaginator. It is unregistered as soon as it is gotten (by its iframe).
  171.     repaginators : new Array(),
  172.     RegisterRepaginator : function (apg)
  173.     {
  174.         this.repaginators.push(apg);
  175.     },
  176.     GetRepaginator : function (iframe)
  177.     {
  178.         for (var i = 0; i < this.repaginators.length; i++)
  179.             if (this.repaginators[i].iframe == iframe)
  180.             {
  181.                 var found = this.repaginators[i];
  182.                 this.repaginators[i] = this.repaginators[this.repaginators.length - 1];
  183.                 this.repaginators.pop();
  184.                 return found;
  185.             }
  186.         return null;
  187.     },
  188.     returnFirstSnapshot : function (doc,node,query)
  189.     {
  190.         return doc
  191.             .evaluate(query,node,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null)
  192.                 .snapshotItem(0);
  193.     },
  194.  
  195.     stop : function()
  196.     {
  197.         if(gContextMenu == null
  198.         || gContextMenu.target == null)
  199.         {            
  200.             var body = window._content.document.getElementsByTagName('body')[0];
  201.         
  202.             if(body != null)
  203.             {
  204.                 body.setAttribute('repagination','isOff');
  205.             }
  206.         }
  207.         else
  208.         {
  209.             var doc = gContextMenu.target.ownerDocument;
  210.             var body = doc.getElementsByTagName('body')[0];
  211.         
  212.             if(body != null)
  213.             {
  214.                 body.setAttribute('repagination','isOff');
  215.             }
  216.         }
  217.     },
  218.     onload : function()
  219.     {
  220.         repagination.menu = document
  221.             .getElementById('repagination_menu');
  222.         var contextMenu = document
  223.             .getElementById('contentAreaContextMenu');
  224.         contextMenu.addEventListener('popupshowing', 
  225.             repagination.popupshowing, true);
  226.         var urlbar = document
  227.             .getElementById('urlbar');
  228.         //urlbar.addEventListener('popupshowing', 
  229.         //    repagination.urlcontextshowing, true);
  230.     },
  231.     urlcontextshowing : function(event)
  232.     {
  233.         var urlbar = document
  234.             .getElementById('urlbar');
  235.         urlbar.removeEventListener('popupshowing', 
  236.             repagination.urlcontextshowing, true);
  237.         /**/
  238.         var copyNode = document.getElementById('repagination_menu2');
  239.         event.originalTarget.appendChild(copyNode);
  240.     },
  241.     popupshowing : function()
  242.     {
  243.  
  244.         if(gContextMenu.onLink == true)
  245.         {
  246.             repagination.menu.hidden = false;
  247.             return;
  248.         }
  249.         
  250.         var doc = gContextMenu.target.ownerDocument;
  251.         var body = doc.getElementsByTagName('body')[0];
  252.         
  253.         if(body == null)
  254.         {
  255.  
  256.             repagination.menu.hidden = true;
  257.             return;
  258.         }
  259.         else
  260.         {
  261.             var result = body.getAttribute('repagination');
  262.             if(result == '')
  263.             {
  264.  
  265.                 repagination.menu.hidden = true;
  266.                 return;
  267.             }
  268.             else if(result == 'isOn')
  269.             {
  270.  
  271.                 repagination.menu.hidden = false;
  272.                 return;
  273.             }
  274.             else
  275.             {
  276.  
  277.                 repagination.menu.hidden = true;
  278.                 return;
  279.             }
  280.         }
  281.     }
  282. };
  283. window.addEventListener('load',repagination.onload,true);
  284. ]]>
  285. </script>
  286.  <popup id="contentAreaContextMenu">
  287.     <menu label="Re-Pagination" insertafter="context-sep-properties" 
  288.         id="repagination_menu">
  289.         <menupopup id="repagination_menupopup" onpopupshowing="event.stopPropagation();">
  290.             <menuitem id="repagination_flatten_nolimit"  
  291.                 label="All"  
  292.                 oncommand="repagination.blast();"/>
  293.             <menu id="repagination_flat_limit_menu" label="Limited">
  294.                 <menupopup  onpopupshowing="event.stopPropagation();">
  295.                     <menuitem label="5" oncommand="repagination.blast(5);"/>
  296.                     <menuitem label="10" oncommand="repagination.blast(10);"/>
  297.                     <menuitem label="15"  oncommand="repagination.blast(15);"/>
  298.                     <menuitem label="20" oncommand="repagination.blast(20);"/>
  299.                     <menuitem label="25" oncommand="repagination.blast(25);"/>
  300.                     <menuitem label="30" oncommand="repagination.blast(30);" />
  301.                     <menuitem label="35" oncommand="repagination.blast(35);"/>
  302.                     <menuitem label="40" oncommand="repagination.blast(40);"/>
  303.                 </menupopup>
  304.             </menu>
  305.                 <menu id="repagination_flat_nolimit_slide" label="SlideShow">
  306.                 <menupopup  onpopupshowing="event.stopPropagation();">
  307.                     <menuitem label="0 sec" oncommand="repagination.blast(0,true);"/>
  308.                     <menuitem label="1 sec" oncommand="repagination.blast(1,true);"/>
  309.                     <menuitem label="2 sec" oncommand="repagination.blast(2,true);"/>
  310.                     <menuitem label="4 sec" oncommand="repagination.blast(4,true);"/>
  311.                     <menuitem label="5 sec" oncommand="repagination.blast(5,true);"/>
  312.                     <menuitem label="8 sec"  oncommand="repagination.blast(8,true);"/>
  313.                     <menuitem label="10 sec"  oncommand="repagination.blast(10,true);"/>
  314.                     <menuitem label="16 sec" oncommand="repagination.blast(16,true);"/>
  315.                     <menuitem label="32 sec" oncommand="repagination.blast(32,true);"/>
  316.                     <menuitem label="64 sec" oncommand="repagination.blast(64,true);" />
  317.                 </menupopup>
  318.             </menu>
  319.             <menuitem id="repagination_stop"
  320.                 label="Stop" 
  321.                 oncommand="repagination.stop();"/>
  322.         </menupopup>
  323.     </menu>
  324. </popup>
  325. <!--window id="main-window">
  326. <popup id="repagination_hide">
  327.     <menu label="Re-Pagination"
  328.         id="repagination_menu2">
  329.         <menupopup id="repagination_menupopup2" onpopupshowing="event.stopPropagation();">
  330.             <menuitem id="repagination_flatten_nolimit2"  
  331.                 label="All"  
  332.                 oncommand="repagination.increment();"/>
  333.             <menu id="repagination_flat_limit_menu2" label="Limited">
  334.                 <menupopup  onpopupshowing="event.stopPropagation();">
  335.                     <menuitem label="5" oncommand="repagination.increment(5);"/>
  336.                     <menuitem label="10" oncommand="repagination.increment(10);"/>
  337.                     <menuitem label="20"  oncommand="repagination.increment(20);"/>
  338.                     <menuitem label="30" oncommand="repagination.increment(30);"/>
  339.                     <menuitem label="50" oncommand="repagination.increment(50);"/>
  340.                     <menuitem label="75" oncommand="repagination.increment(75);" />
  341.                     <menuitem label="100" oncommand="repagination.increment(100);"/>
  342.                     <menuitem label="250" oncommand="repagination.increment(250);"/>
  343.                 </menupopup>
  344.             </menu>
  345.                 <menu id="repagination_flat_nolimit_slide2" label="SlideShow">
  346.                 <menupopup  onpopupshowing="event.stopPropagation();">
  347.                     <menuitem label="0" oncommand="repagination.increment(0,true);"/>
  348.                     <menuitem label="1" oncommand="repagination.increment(1,true);"/>
  349.                     <menuitem label="2" oncommand="repagination.increment(2,true);"/>
  350.                     <menuitem label="4" oncommand="repagination.increment(4,true);"/>
  351.                     <menuitem label="5" oncommand="repagination.increment(5,true);"/>
  352.                     <menuitem label="8"  oncommand="repagination.increment(8,true);"/>
  353.                     <menuitem label="10"  oncommand="repagination.increment(10,true);"/>
  354.                     <menuitem label="16" oncommand="repagination.increment(16,true);"/>
  355.                     <menuitem label="32" oncommand="repagination.increment(32,true);"/>
  356.                     <menuitem label="64" oncommand="repagination.increment(64,true);" />
  357.                 </menupopup>
  358.             </menu>
  359.             <menuitem id="repagination_stop2"
  360.                 label="Stop" 
  361.                 oncommand="repagination.stop();"/>
  362.         </menupopup>
  363.     </menu>
  364. </popup>
  365. </window-->
  366. </overlay>